package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 实现问题：
 * 1.多了三个字段  @jsonIgnore
 * 2.逻辑删除没有真正的生效 @tableLogic
 */
@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {
    @Autowired
    private PaymentTypeService paymentTypeService;
    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        List<PaymentType> paymentTypeList = paymentTypeService.list();
        return Result.ok(paymentTypeList);
    }

    /**
     * 问题
     * 1.删除逻辑字段没有默认值
     * 解决：1. 在baseentity中 isDeleted = 0 不推荐
     *      2.数据库设置默认值  alter table xx modify is_delete int default 0;
     * 2.创建时间和修改时间没有默认值
     *     1.手动解决 在handle方法中进行判断！ 保存
     *     2.mybatis 自动填充功能
     * @param paymentType
     * @return
     */

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        boolean saveOrUpdate = paymentTypeService.saveOrUpdate(paymentType);
       return saveOrUpdate ? Result.ok() : Result.fail();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        boolean removeById = paymentTypeService.removeById(id);
        return removeById? Result.ok(): Result.fail();
    }

}















